malloy logoMalloy Documentation

Segment Maps

The plugin currently supports US maps. Segement maps take as input 4 columns: start latitude , start longitude, end latitude, and end longitude of the segment. The model and data styles for the subsequent examples are:

define airports is (explore 'malloy-data.faa.airports'
  primary key code
  airport_count is count(*)
);

define flights is (explore 'malloy-data.faa.flights'
  primary key id2

  origin_code renames origin
  destination_code renames destination
  origin is join airports on origin_code,
  destination is join airports on destination_code

  flight_count is count()

  routes_map is (reduce
    origin.latitude
    origin.longitude
    latitude2 is destination.latitude
    longitude2 is destination.longitude
    flight_count
  )


);

and data styles are

{
  "routes_map": {
    "renderer": "segment_map"
  }
}

Run as a simple query

Departing from Chicago

explore flights : [dep_time : @2003-02, origin.code : 'ORD']
| routes_map
7008009001,000flight_count

Run as a nested subtable

explore flights : [dep_time : @2003-02, origin.code : 'ORD']
| reduce
  routes_map
routes_​map
2004006008001,000flight_count

Run as a trellis

By calling the configured map as a nested query, a trellis is formed.

explore flights : [dep_time : @2003-02, origin.code : 'ORD']
| reduce
  carrier
  flight_count
  routes_map
carrier flight_​count routes_​map
UA 9,443 100200300400flight_count
AA 7,255 100200300400flight_count
MQ 4,975 50100150200flight_count
DH 3,906 50100150flight_count
NW 702 150200250300350flight_count

Run as a trellis, repeated with different filters

explore flights : [dep_time : @2003-02]
| reduce : [origin.code : 'ORD'|'SFO'|'JFK']
  carrier
  flight_count
   ord is routes_map : [ origin.code: 'ORD']
   sfo is routes_map : [ origin.code: 'SFO']
   jfk is routes_map : [ origin.code: 'JFK']
carrier flight_​count ord sfo jfk
UA 13,584 100200300400flight_count 100200300400flight_count 50100150flight_count
AA 9,271 100200300400flight_count 50100150200flight_count 50100150200flight_count
MQ 5,885 50100150200flight_count 1132flight_count 50100150flight_count
DH 4,332 50100150flight_count NaNflight_count 50100150200flight_count
OO 2,338 NaNflight_count 50100150200250300flight_count NaNflight_count